package com.newtouch.cq.mybatis.util;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.log.Log;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.cq.lang.em.BaseExceptionEnum;
import com.newtouch.cq.lang.exception.MccBizException;
import com.newtouch.cq.lang.util.LogUtil;

import java.io.Serializable;

/**
 * 数据工具类
 * @author Alex
 */
public class DbUtil {


    /**
     * 查询数据库是否包含某个id的数据，没有抛出异常
     * @param baseMapper
     * @param id
     */
    public static void containId(BaseMapper baseMapper, Serializable id, Log log) {
        if(ObjectUtil.isNull(baseMapper.selectById(id))){
            LogUtil.error(log, BaseExceptionEnum.FAIL,"查询无相关数据");
            throw new MccBizException(BaseExceptionEnum.FAIL).setMessage("查询无相关数据");
        }
    }
}
